// TypeScript file

class AutoRotation extends eui.Component {
    private autoRotationBtn: eui.Button;
    private numPanel: NumPanel2;
    private rotationNum:number = 0;
    private numContainer:eui.Component;
    private context:any;
    

    public constructor(num:number,context:any) {
        super();
        this.rotationNum = num;
        this.context = context;
        this.skinName="m_auto_ratation_new";
        this.numPanel = new NumPanel2(15 * 0.8, 22.5 * 0.8, "w_");
        this.numPanel.setNum(100);
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
       
    }

    private onAddToStage(event: egret.Event) {
        //this.draw();
        this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
        this.numPanel.setScale(1);
        this.numPanel.setNum(this.rotationNum);
        this.numContainer.addChild(this.numPanel);
        this.numPanel.x = this.numContainer.width/2 - 10;
        this.numPanel.y = this.numContainer.height/2 -15;
        this.setAutoAvbleState();
        this.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.begin,this);
		this.addEventListener(egret.TouchEvent.TOUCH_END,this.end,this);
        this.autoRotationBtn.touchEnabled = false;
        this.visible = false;
    }


    	/**
	 * 设置为可用状态
	 */
    public setAutoAvbleState() {
        // this.skinName = "m_auto_rotation";
        if(this.rotationNum == 0) return;
        this.touchEnabled = true;
        this.name = "";
        this.currentState = "auto_rotation_btn";
        this.visible = true;
    }

    public setAutoReset(num){
        // this.touchEnabled = true;
        // this.name = "";
        // this.currentState = "auto_rotation_btn";
        // this.setNumber(num)
    }
	/**
	 * 设置为不可用状态
	 */
    public setAutoDisState() {
        // alert();
        this.currentState = "dis";
        // this.skinName = "test";
        //this.touchEnabled = false;
        // this.name = null;
        this.currentState = "disabled";
         
    }

    /**
 * 设置为可用状态
 */
    public setStopAvbleState() {
        // if(this.rotationNum == 0) return;
        // // this.skinName = "m_auto_rotation_stop";
        // this.touchEnabled = true;
        // this.autoRotationBtn.name = "stoproation";
        // this.currentState = "";
        //  this.autoRotationBtn.touchEnabled = true;
    }
	/**
	 * 设置为不可用状态
	 */
    public setStopDisState() {
        // this.skinName = "m_auto_rotation_stop";
        // this.touchEnabled = false;
        // this.autoRotationBtn.name = null;
        // this.currentState = "disabled";
        //  this.autoRotationBtn.touchEnabled = false;
    }

    public setNumber(num:number){
        this.rotationNum = num;
        this.numPanel.setNum(num);
        this.numPanel.x = this.numContainer.width/2 ;
        this.numPanel.y = this.numContainer.height/2 ;
    }
    
    public getNumber():number
    {
        return this.rotationNum;
    }

    private begin(){
		this.scaleX = 0.5;
		this.scaleY = 0.5;
	}

	private end()
	{
		this.scaleX = 0.6;
		this.scaleY = 0.6;
        //this.touchEnabled = false;
        if( this.currentState == "auto_rotation_btn"){
            this.context.gunDeal.gunStop();
            this.visible = false;
        }
	}


}